year=int(input("请输入年份："))
month=int(input("请输入月份："))
print("----------------万年历----------------")
print("------------%d年%d月------------"%(year,month))
print("星期一\t星期二\t星期三\t星期四\t星期五\t星期六\t星期日\t")

day=0
for i in range(1900,year):
    if(i%4==0 and i%100!=0) or i%400==0:
        day+=365
    else:
        day+=365

def days(x,y):
    if(y%4==0 and y%100!=0) or y%400==0:
        a=[0,31,29,31,30,31,30,31,31,30,31,30,31]
        return a[x]
    else:
        a = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        return a[x]

monthdays=0
for j in range(0,month):
    monthdays+=days(j,year)
totaldays=monthdays+day
space=int(totaldays%7)
for i in range(space):
    print('\t\t',end="")
for k in range(1,days(month,year)+1):
    print("%3d\t\t"%k,end="")
    if(k+space)%7==0:
        print('\n')